﻿using System;
using System.Configuration;
using System.Net.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;
using System.IO;

public partial class contact_us : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    //private void SendMail()
    //{
    //    string to = txtTo.Text;
    //    int port = 587;
    //    string subject = txtSubject.Text;
    //    string content = txtContent.Text;
    //    SmtpClient client = new SmtpClient();
    //    client.EnableSsl = true;
    //    client.Port = port;
    //    client.Host = "smtp.gmail.com";
    //    client.Credentials = new NetworkCredential("timeislifesgift@gmail.com", "p@sswprd");
    //    MailAddress from = new MailAddress("nguyentrinhhoangtruc@gmail.com", "yeuanhmaithoi");
    //    MailAddress toAddress = new MailAddress(to);
    //    MailMessage message = new MailMessage(from, toAddress);
    //    message.Body = content;
    //    message.Subject = subject;
    //    try
    //    {
    //        client.Send(message);
    //        lbMessage.Text = "Send mail sucessfully!!!";
    //    }
    //    catch (Exception ex)
    //    {
    //        lbMessage.Text = ex.Message;
    //    }
    //}

    //protected void btnSend_Click(object sender, EventArgs e)
    //{
    //    SendMail();
    //}

    //public static String FormAddress
    //{
    //    get
    //    {
    //        SmtpSection cfg = (SmtpSection)ConfigurationManager.GetSection
    //        ("system.net/mailSettings/smtp");
    //        return cfg.Network.UserName;
    //    }
    //}
    //public string SendMail(string subject, string body, string to, bool isHtml, bool isSSL)
    //{
    //    //SmtpClient client = new SmtpClient(smtp);
    //    //client.EnableSsl = true;
    //    try
    //    {
    //        using (MailMessage mail = new MailMessage())
    //        {
    //            mail.To.Add(to);
    //            mail.From = new MailAddress(FormAddress, "Laptop Secondhand");
    //            mail.Subject = subject;
    //            mail.Body = body;
    //            mail.IsBodyHtml = isHtml;
    //            SmtpClient client = new SmtpClient();
    //            client.EnableSsl = true;
    //            client.Send(mail);
    //        }
    //    }
    //    catch (SmtpException ex)
    //    {
    //        return ex.Message;
    //    }
    //    return "Send email successful!";
    //}


    //protected void btnSend_Click(object sender, EventArgs e)
    //{
    //    StreamReader sr = new StreamReader(Server.MapPath("try.htm"));
    //    sr = File.OpenText(Server.MapPath("try.htm"));
    //    string content = sr.ReadToEnd();
    //    content = content.Replace("[Com]", txtCompany.Text);
    //    content = content.Replace("[Sender]", txtName.Text.Trim());
    //    content = content.Replace("[Address]", txtAddress.Text);
    //    content = content.Replace("[Phone]", txtPhone.Text);
    //    content = content.Replace("[Email]", txtEmail.Text);
    //    content = content.Replace("[Content]", txtCmt.Text);
    //    content = content.Replace("[DateTime]", DateTime.Now.ToShortDateString());
    //    try
    //    {
    //        Response.Write(SendMail("Contact us", content, txtEmail.Text.Trim(), true, false));
    //    }
    //    catch (Exception ex)
    //    {
    //        Response.Write(ex.Message);
    //    }
    //}

    //cai nay duoc na
    protected void SendMail()
    {
<<<<<<< .mine
        // Gmail Address from where you send the mail
        var fromAddress = "group7.pttkhdt@gmail.com";
        // any address where the email will be sending
        var toAddress = YourEmail.Text.ToString();
        //Password of your gmail address
        const string fromPassword = "linhnguyen";
        // Passing the values and make a email formate to display
        string subject = YourSubject.Text.ToString();
        string body = "Hi, " + YourName.Text + "<br /> Thanks for contact us. We will order the message later! <br />" + "\n";
        body += "Email: " + YourEmail.Text + "\n";
        body += "Subject: " + YourSubject.Text + "\n";
        body += "Question: \n" + Comments.Text + "\n" + "<br /> Thamnks and Regards <br />";
        // smtp settings
        var smtp = new System.Net.Mail.SmtpClient();
=======
        // Gmail Address from where you send the mail
        var fromAddress = "group7.pttkhdt@gmail.com";
        // any address where the email will be sending
        var toAddress = YourEmail.Text.ToString();
        //Password of your gmail address
        const string fromPassword = "linhnguyen";
        // Passing the values and make a email formate to display
        string subject = YourSubject.Text.ToString();
        string body = "From: " + YourName.Text + "\n";
        body += "Email: " + YourEmail.Text + "\n";
        body += "Subject: " + YourSubject.Text + "\n";
        body += "Question: \n" + Comments.Text + "\n";
        // smtp settings
        var smtp = new System.Net.Mail.SmtpClient();
>>>>>>> .r56
        {
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
            smtp.Timeout = 20000;
        }
        // Passing values to smtp object
        smtp.Send(fromAddress, toAddress, subject, body);
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
<<<<<<< .mine
            //here on button click what will done 
            SendMail();
            DisplayMessage.Text = "Thanks for contacting us. We will get back to you in 24Hrs";
            DisplayMessage.Visible = true;
            YourSubject.Text = "";
            YourEmail.Text = "";
            YourName.Text = "";
            Comments.Text = "";
=======
            //here on button click what will done 
            SendMail();
            DisplayMessage.Text = "Your Comments after sending the mail";
            DisplayMessage.Visible = true;
            YourSubject.Text = "";
            YourEmail.Text = "";
            YourName.Text = "";
            Comments.Text = "";
>>>>>>> .r56
        }
        catch (Exception) { }
    }
}